"""
 定义POM基类，作为整个POM结构下的工具类，用于后续的PO对象进行调用

"""
from time import sleep


# 基类
class BasePage:

    # 构造函数
    def __init__(self, driver):
        self.driver = driver

    def get_driver(self):
        return self.driver

    # 元素定位 3.0 :基于str来生成元素定位
    def locator(self, loc):
        return self.driver.find_element(*loc)

    # 元素的输入
    def input(self, loc, txt):
        self.locator(loc).send_keys(txt)

    def select(self, loc, target):

        self.locator(loc).click()
        sleep(1)
        self.locator(target).click()

    # 元素的点击
    def click(self, loc):
        self.locator(loc).click()

    # 访问指定URL
    def visit(self, url):
        self.driver.get(url)

    # 关闭浏览器 ，释放资源
    def quit(self):
        sleep(3)
        self.driver.quit()

    # 页面最大化
    def max_window(self):
        self.driver.maximize_window()

    def snapshot(self, filename):
        self.driver.save_screenshot(filename)

    def assert_url(self, expect):
        cur_url = self.driver.current_url
        return cur_url == expect
